import { Category } from "server/models/Category";
import { successResponse, errorResponse } from "server/utils/response";

export default defineEventHandler(async () => {
  try {
    try {
      const categories = await Category.getActiveCategories();
      return successResponse(categories, "获取分类列表成功");
    } catch (dbError) {
      console.warn("数据库查询失败，使用模拟数据:", dbError);
    }
  } catch (error) {
    console.error("获取分类列表失败:", error);
    return errorResponse(
      "获取分类列表失败",
      error instanceof Error ? error.message : "未知错误"
    );
  }
});
